<template>
  <div>
    <el-row style="margin-left:10%;margin-top:10px">
      <el-col :span="23">
        <el-steps :active="step" style="margin-left:10%;font-size:39px;cursor:pointer;">
          <el-step title="步骤 1" style="text-align:center" icon="edit" description="添加人员的特殊信息">
          </el-step>
          <el-step title="步骤 2" icon="upload" description="信息预览(提交)">
          </el-step>
        </el-steps>
        <div style="margin-top:30px">
          <div v-if="step==1">
            <el-row style="margin-left:10%">
              <div style="margin-bottom:10px">
                <el-tag style="font-size:20px;height:25px;" type="danger">请选择要添加的人员类型(单选):</el-tag>
              </div>
              <el-radio-group v-model="specialValue" size="medium">
                <el-radio-button v-for="item in specialTypes" v-if="item.specialPopulationTypeValue!='04'&&item.specialPopulationTypeValue!='05'" @click.native="changeValue(item.specialPopulationTypeValue)" :label="item.specialPopulationTypeName" :key="item.specialPopulationTypeValue"></el-radio-button>
                <!-- <el-radio-button label="重点青少年" @click.native="addKeyYoung('06')"></el-radio-button> -->
                <!-- <el-radio-button label="重点上访人员" @click.native="addKeyPetitioner('07')"></el-radio-button> -->
              </el-radio-group>
            </el-row>
            <el-row>
              <div v-if="specialId=='01'" style="width:80%;margin-left:5%;margin-top:20px">
                <emancipist-form :emancipistForm="Emancipist" :DangerousEvaulationType="DangerousEvaulationType" :ConnectionType="ConnectionType" :PlacementType="PlacementType" :showButton="false"></emancipist-form>
              </div>
              <div v-if="specialId=='02'" style="width:80%;margin-left:5%;margin-top:20px">
                <community-correctioner-form :communityCorrectionerForm="communityCorrectioner" :CorrectingType=" CorrectingType" :AcceptType="AcceptType" :GroupMemberType="GroupMemberType" :StopCorrectionType="StopCorrectionType" :CaseType="CaseType" :showButton="false"></community-correctioner-form>
              </div>
              <div v-if="specialId=='03'" style="width:80%;margin-left:5%;margin-top:20px">
                <severe-psychotic-form :severePsychoticForm="SeverePsychotic" :EconomicSituationType="EconomicSituationType" :currentDiagnosisType="currentDiagnosisType" :dangerousEvaulationLevelType="dangerousEvaulationLevelType" :treatmentSituationType="treatmentSituationType" :showButton="false"></severe-psychotic-form>
              </div>
              <div v-if="specialId=='04'" style="width:80%;margin-left:5%;margin-top:20px">
                <DrugAddictsForm :DrugAddicts="DrugAddicts" :ControlSituationType="controlSituationType" :drugReasonType="drugReasonType" :drugResultType="drugResultType" :showButton="false"></DrugAddictsForm>
              </div>
              <div v-if="specialId=='05'" style="width:80%;margin-left:5%;margin-top:20px">
                <AIDSdiseaseForm :AIDSdisease="AIDSdisease" :InfectedWayType="InfectedWayType" :AIDSAttentionType="AIDSAttentionType" :AIDSReceiveCType="AIDSReceiveCType" :CaseType="CaseType" :showButton="false"></AIDSdiseaseForm>
              </div>
              <div v-if="specialId=='06'" style="width:80%;margin-left:5%;margin-top:20px">
                <key-young-form :MyForm="keyYoungForms" :showButton="false"></key-young-form>
              </div>
              <div v-if="specialId=='07'" style="width:80%;margin-left:5%;margin-top:20px">
                <key-petitioner :form="KeyPetitioner" :showButton="false"></key-petitioner>
              </div>
            </el-row>
          </div>
          <div v-if="step==2">
            <el-tabs style="width:90%" type="border-card">
              <el-tab-pane label="基本信息">
                <baisc-info-table :memberInfo='form' :fatherAndChildVO="fatherAndChildVO" :imageUrl='imageUrl'></baisc-info-table>
              </el-tab-pane>
              <el-tab-pane label="特殊信息">
                <div v-if="specialId=='01'" style="width:80%;margin-left:5%;margin-top:20px">
                  <emancipist-form :emancipistForm="Emancipist" :DangerousEvaulationType="DangerousEvaulationType" :ConnectionType="ConnectionType" :PlacementType="PlacementType" :showButton="false"></emancipist-form>
                </div>
                <div v-if="specialId=='02'" style="width:80%;margin-left:5%;margin-top:20px">
                  <community-correctioner-form :communityCorrectionerForm="communityCorrectioner" :CorrectingType=" CorrectingType" :AcceptType="AcceptType" :GroupMemberType="GroupMemberType" :StopCorrectionType="StopCorrectionType" :CaseType="CaseType" :showButton="false"></community-correctioner-form>
                </div>
                <div v-if="specialId=='03'" style="width:80%;margin-left:5%;margin-top:20px">
                  <severe-psychotic-form :severePsychoticForm="SeverePsychotic" :EconomicSituationType="EconomicSituationType" :currentDiagnosisType="currentDiagnosisType" :dangerousEvaulationLevelType="dangerousEvaulationLevelType" :treatmentSituationType="treatmentSituationType" :showButton="false"></severe-psychotic-form>
                </div>
                <div v-if="specialId=='04'" style="width:80%;margin-left:5%;margin-top:20px">
                  <DrugAddictsForm :DrugAddicts="DrugAddicts" :ControlSituationType="controlSituationType" :drugReasonType="drugReasonType" :drugResultType="drugResultType" :showButton="false"></DrugAddictsForm>
                </div>
                <div v-if="specialId=='05'" style="width:80%;margin-left:5%;margin-top:20px">
                  <AIDSdiseaseForm :AIDSdisease="AIDSdisease" :InfectedWayType="InfectedWayType" :AIDSAttentionType="AIDSAttentionType" :AIDSReceiveCType="AIDSReceiveCType" :CaseType="CaseType" :showButton="false"></AIDSdiseaseForm>
                </div>
                <div v-if="specialId=='06'" style="width:80%;margin-left:5%;margin-top:20px">
                  <key-young-form :MyForm="keyYoungForms" :showButton="false"></key-young-form>
                </div>
                <div v-if="specialId=='07'" style="width:80%;margin-left:5%;margin-top:20px">
                  <key-petitioner :form="KeyPetitioner" :showButton="false"></key-petitioner>
                </div>
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
      </el-col>
      <el-col :span="24">
        <div class="preDiv">
          <i v-if="step!=1" class="fa fa-angle-double-left fa-5x" @click="goPre()"></i>
          <div v-if="step!=1" class="directionFont" @click="goPre()">
            上一步
          </div>
        </div>
        <div class="nextDiv">
          <i v-if="step!=2" class="fa fa-angle-double-right fa-5x" @click="goNext"></i>
          <div v-if="step!=2" class="directionFont" @click="goNext">
            下一步
          </div>
          <i v-if="step==2" class="fa fa-upload fa-5x" @click="submit"></i>
          <div v-if="step==2" class="directionFont" @click="submit">
            提交数据
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import addPopulation from "../../components/common/addPopulation";

// 基本表格组件
import BaiscInfoTable from "../../components/ZzOrgManage/servedBasicTable";

// 特殊人口组件
import DrugAddictsForm from "../../components/ZzOrgManage/extendDrugAddicts";
import AIDSdiseaseForm from "../../components/ZzOrgManage/extendAIDsdisease";
import SeverePsychoticForm from "../../components/ZzOrgManage/extendSeverePsychotic";
import CommunityCorrectionerForm from "../../components/ZzOrgManage/extendCommunityCorrectioner";
import EmancipistForm from "../../components/ZzOrgManage/extendEmancipist";
import keyYoungForm from "../../components/ZzOrgManage/keyYoungForm";
import KeyPetitioner from "../../components/ZzOrgManage/extendKeyPetitioners";

import * as api from "@/api/zonghezhili/duiwujianshe";
import * as SpeApi from "@/api/specialPopulation/index";

export default {
  components: {
    addPopulation: addPopulation,
    BaiscInfoTable: BaiscInfoTable,
    DrugAddictsForm: DrugAddictsForm,
    AIDSdiseaseForm: AIDSdiseaseForm,
    SeverePsychoticForm: SeverePsychoticForm,
    CommunityCorrectionerForm: CommunityCorrectionerForm,
    EmancipistForm: EmancipistForm,
    keyYoungForm: keyYoungForm,
    keyPetitioner: KeyPetitioner
  },
  watch: {
    specialValue(val, oldval) {
      if (val === "刑满释放人员") {
        this.obj = this.Emancipist;
      } else if (val === "社区矫正人员") {
        this.obj = this.communityCorrectioner;
      } else if (val === "肇事肇祸等严重精神障碍患者") {
        this.obj = this.SeverePsychotic;
      } else if (val === "吸毒人员") {
        this.obj = this.DrugAddicts;
      } else if (val === "重点青少年") {
        this.obj = this.keyYoungForms;
      } else if (val === "重点上访人员") {
        this.obj = this.KeyPetitioner;
      } else {
        this.obj = this.AIDSdisease;
      }
    }
  },
  data() {
    return {
      imageUrl: null,
      step: 1,
      fatherAndChildVO: {},
      form: {
        imgId: -1, //头像的id
        servedPersonTypeValue: "01", // 服务对象类型
        // servedPersonTypeName: '流动人口',  // '服务对象的类型，包括01=户籍人口，02=流动人口，03=留守人员，99=境外人员。';
        certifID: "", // 身份证号
        name: "", // 姓名
        nameUsed: "", // 曾用名
        sex: 1, // 性别
        birthDate: "", // 出生日期，格式为“YYYYMMDD”
        ethnicity: "", // 民族
        nativePlace: "", // 籍贯，出生地，老家
        politics: "", // 政治面貌
        maritalStatus: "", // 婚姻状况
        education: null, // 学历
        religiousBelief: null, // 宗教信仰，后期需要符合标准编码
        careerType: null, // 职业类别
        career: "", // 职业
        mobileTel: "", // 移动电话
        fixedTel: "", // 固定电话
        isSpecialPopulation: 0, // 是否为特殊人群
        servedPlace: "", // 服务处所
        domicileAddress: "", // 户籍地
        domicileAddressDetail: "", // 户籍门(楼)详细地址',
        presentAddress: "", // 现住地',
        presentAddressDetail: "" // 现住地门(楼)详细地址',
      },
      keyYoungForms: {
        keyYoungersID: "", //             int not null auto_increment,
        certifID: "", //                  '身份证号. 编码应符合GB 11643',
        populationTypeValue: "", //       '人员类型，编码见GBT 31000-2015文件之5.41',
        familySituationTypeValue: "", //  '家庭情况，编码见GBT 31000-2015文件之5.42',
        guardianCertifID: "", //          '监护人身份证号. 编码应符合GB 11643',
        guardianName: "", //                varchar(50),
        relatedtoGuardianTypeValue: "", // '与监护人关系，编码见GB/T 4761',
        guardianContact: "", //            '监护人联系方式，手机号码或固定电话号码',
        guardianAddressDetail: "", //      '监护人居住地详细地址',
        isCrime: "", //                    '是否犯罪？0表示没有，1表示是',
        crimeInf: "", //                   '违法犯罪情况',
        helperName: "", //                 '帮扶人姓名',
        helperContact: "", //              '帮扶人联系方式，手机号码或固定电话号码',
        helpingSolutionTypeValue: "", //   '帮扶手段类型编码，见GBT 31000-2015文件之5.43',
        helpingInf: "" //                  '帮扶情况',
      },
      DrugAddicts: {
        // 吸毒信息扩展表
        extendCorrectionerID: 1,
        certifID: "", // '身份证号'
        firstFoundDate: "", // '吸毒初次被发现的日期',
        controlSituationTypeValue: "", // '管控情况类型编码',
        controlSituationTypeName: "", // 管控类型名称
        controlOfficerName: "", // comment '管控人姓名',
        controlOfficerContact: "", // comment '管控人联系方式，手机号码或固定电话号码',
        helpingInf: "", // comment '帮扶情况',
        helperName: "", // comment '帮扶人姓名',
        helperContact: "", // comment '帮扶人联系方式',
        isCrime: 1, // '是否有犯罪史？0表示无，1表示有',
        crimeInf: "", // comment '犯罪情况描述',
        drugReasonTypeValue: "", // comment '吸毒原因类型编码，标准GA 332.2',
        drugResultTypeValue: "" // comment '吸毒后果类型编码，标准GA 332.4',
      },
      AIDSdisease: {
        extendCorrectionerID: 1,
        certifID: "", // '身份证号'
        infectedWayTypeValue: null, // '感染途径类型编码',
        isCrime: 1, // '是否有犯罪史？0表示无，1表示有',
        crimeInf: "", // comment '犯罪情况描述',
        caseType: "", // comment '案件类别，编码符合GA 240.1',
        aIDSAttentionTypeValue: null, // comment '艾滋病关注类型编码',
        helpingInf: "", // comment '帮扶情况',
        helperName: "", // comment '帮扶人姓名',
        helperContact: "", // comment '帮扶人联系方式',
        aIDSReceiveCTypeValue: null, // comment '艾滋病收治情况类型编码',
        receiveCOrganization: "" // comment '收治机构名称',
      },
      SeverePsychotic: {
        // 精神病扩展信息表
        isTroublemaking: 1,
        isSubsistenceAllowances: 0,
        troublemakingNumber: 0,
        currentDiagnosisTypeValue: null,
        dangerousEvaulationLevelTypeValue: null,
        treatmentSituationTypeValue: null,
        familyEconomicSituationTypeValue: null
      },
      communityCorrectioner: {
        // 社区改造扩展信息表
        originalSentenceStartDate: "",
        originalSentenceEndDate: "",
        correctionStartDate: "",
        correctionEndDate: "",
        acceptTypeValue: null,
        correctingTypeValue: null,
        caseTypeValue: null,
        groupMemberTypeValue: null,
        stopCorrectionTypeValue: null,
        isCreatingCorrectionGroup: 1,
        isMissingControl: 1,
        isOutofControl: 1,
        isRecidivist: 1,
        isRecidivism: 1 //是否重新犯罪
      },
      KeyPetitioner: {
        tEKeyPID: "",
        certifID: "",
        activityCode: "",
        measuresCode: "",
        economicSourceCode: "",
        steadyStateCode: "",
        steadyGradeCode: "",
        petitionTypeCode: "",
        petitionStatusCode: "",
        reasonsPetitionReasons: "",
        detailSituation: "",
        treatmentDetailSituation: "",
        workCoordinationDetails: "",
        talkEducationAdmonitionDetails: ""
      },
      Emancipist: {
        // 刑满释放人员扩充信息表
        extendEmancipistID: "",
        certifID: "",
        isRecidivist: "",
        originalSinType: "",
        originalSentence: "",
        imprisonmentAddress: "",
        releaseDate: "",
        dangerousEvaulationTypeValue: "",
        connectionDate: "",
        connectionTypeValue: "",
        placementDate: "",
        placementTypeValue: "",
        noPlacementReason: "",
        helpingSituation: "",
        isRecidivism: "",
        recidivismCharge: ""
      },

      specialValue: "刑满释放人员", // 选择的特殊人口种类
      specialId: "01",
      specialTypes: [], // 特殊人口类型的编码等待服务器上传
      CareerType: [], // 职业类别
      ReligiousBeliefType: [], // 宗教信仰
      EducationType: [], //  学历
      // 常住人口
      ConsistforPersonHouseType: [], //常住户籍人口编码
      // 流动人口所需编码
      UnSettledReasonType: [], // 未落户原因
      FolatingReasonType: [], // 流入原因编码
      CertificateType: [], // 办证类型编码
      HouseType: [], //住所类型编码
      // 留守人口所需编码表
      StayedPersonType: [], // 留守人口类型
      HealthStatusType: [], // 健康状况编码

      // 特殊人群之艾滋病所需编码
      InfectedWayType: [], // 感染途径类型编码
      CaseType: [], // 案件类别
      AIDSAttentionType: [], // 艾滋病关注类型编码
      AIDSReceiveCType: [], // 艾滋病收治情况类型编码

      // 特殊人群之吸毒记录
      controlSituationType: [], // 管控类型编码
      drugReasonType: [], // 吸毒原因类型编码(缺失)
      drugResultType: [], // 吸毒后果编码(缺失)

      // 特殊人群之刑满释放人员
      DangerousEvaulationType: [], // 危险评估类型
      ConnectionType: [], // 衔接情况类型
      PlacementType: [], // 安置情况类型

      // 特殊人群之社区矫正人员
      CorrectingType: [], // 矫正类型编码
      AcceptType: [], // 接收方式
      GroupMemberType: [], // 矫正成员小组编码
      StopCorrectionType: [], //终止矫正类型

      // 特殊人群之精神病所需编码
      EconomicSituationType: [],
      currentDiagnosisType: [],
      dangerousEvaulationLevelType: [],
      treatmentSituationType: [],

      // PopulationType: [],
      // FamilySituationType: [],
      // HelpingSolutionType: [],
      // RelatedtoGuardianType: [],

      obj: {}
    };
  },
  methods: {
    handleChange(){

    },
    addKeyPetitioner(id) {
      this.specialId = id;
    },
    addKeyYoung(id) {
      this.specialId = id;
    },
    changeValue(id) {
      this.specialId = id;
    },
    goPre() {
      if (this.step > 1) {
        this.step = this.step - 1;
      }
    },
    goNext() {
      if (this.obj.certifID == "") {
        this.$notify({
          type: "error",
          message: "请先添加完整的基本信息"
        });
        return;
      }
      if (this.step < 2) {
        this.step = this.step + 1;
        SpeApi.fetchSpecialPeronDetail(this.obj.certifID, "01").then(res => {
          this.form = res.data.basic[0];
          this.fatherAndChildVO = res.data.fatherAndChildVO;
        });
      }
    },
    getImageUrl(url) {
      this.imageUrl = url;
    },
    submit() {
      SpeApi.addSpecialPerson(this.obj, this.specialId).then(res => {
        if (res.data) {
          this.$message({
            type: "success",
            message: "添加成功!"
          });
        } else {
          this.$message({
            type: "success",
            message: "添加失败!"
          });
        }
      });

      this.$confirm("是否继续添加?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$router.go(0);
        })
        .catch(() => {
          this.$router.go("/tsrkManage");
        });
    }
  },
  mounted() {
    this.$store.commit("INIT_PAGE", "");
    this.obj = this.Emancipist;
    api.fetchServedPersonManageTypes().then(res => {
      this.EducationType = res.data.codeEducationTypeMapper; // 学历
      this.CareerType = res.data.codeCareerType; // 职业类别
      this.CaseType = res.data.codeCaseType; // 案件类型
      this.ReligiousBeliefType = res.data.codeReligiousBeliefType;
      this.specialTypes = res.data.codeSpecialPopulationType; //特殊人员类型
      this.ConsistforPersonHouseType = res.data.codeConsistforPersonHouseType; //常住户籍人口编码
      this.FolatingReasonType = res.data.codeFloatingReasonType; // 流入原因编码
      this.UnSettledReasonType = res.data.codeUnSettledReasonType; // 未落户原因
      this.CertificateType = res.data.codeCertificateType; // 办证类型编码
      this.HouseType = res.data.codeHouseType; // 住所类型编码
      this.StayedPersonType = res.data.codeStayedPersonType; // 留守人口类型
      this.HealthStatusType = res.data.codeHealthStatusType; // 健康状况编码

      this.InfectedWayType = res.data.codeInfectedWayType; // 感染途径编码
      this.AIDSAttentionType = res.data.codeaidsAttentionType; // 艾滋病关注类型编码
      this.AIDSReceiveCType = res.data.codeAIDSReceiveCType; // 艾滋病收治编码

      this.controlSituationType = res.data.codeControlSituationType; // 控制类型编码
      this.drugReasonType = res.data.codeDrugReasonType; // 吸毒原因编码
      this.drugResultType = res.data.codeDrugResultType; // 吸毒后果编码

      this.DangerousEvaulationType = res.data.codeDangerousEvaulationType; // 危险评估类型
      this.ConnectionType = res.data.codeConnectionType; // 衔接类型编码
      this.PlacementType = res.data.codePlacementType; // 安置情况

      this.CorrectingType = res.data.codeCorrectingType; // 矫正编码
      this.AcceptType = res.data.codeAcceptType; // 接收方式
      // this.GroupMemberType = res.data.
      this.StopCorrectionType = res.data.codeStopCorrectionType; // 终止矫正

      this.EconomicSituationType = res.data.codeFamilyEconomicSituationType;
      this.currentDiagnosisType = res.data.codeCurrentDiagnosisType;
      this.dangerousEvaulationLevelType =
        res.data.codeDangerousEvaulationLevelType;
      this.treatmentSituationType = res.data.codeTreatmentSituationType;

      this.PopulationType = res.data.codePopulationType;
      this.FamilySituationType = res.data.codeFamilySituationType;
      this.HelpingSolutionType = res.data.codeHelpingSolutionType;
      this.RelatedtoGuardianType = res.data.codeRelatedtoGuardianType;
    });
  }
};
</script>

<style scoped>
.preDiv {
  position: absolute;
  top: 300px;
  left: -11%;
  cursor: pointer;
  color: #58b7ff;
  text-align: center;
  margin-left: 10px;
}
.nextDiv {
  position: absolute;
  top: 300px;
  right: 0;
  cursor: pointer;
  color: #58b7ff;
  text-align: center;
  margin-right: 10px;
}
.directionFont {
  color: #1d8ce0;
  font-weight: bold;
  text-align: center;
}
</style>
